home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 April / Software of the Month Club 1996 April.iso / pc / os2 / psutils / cmd / includ~1.cmd < prev    next >
OS/2 REXX Batch file  |  1996-02-21  |  1KB  |  49 lines

  1. extproc perl5 -x
  2. #! perl5
  3.  
  4. # includeres: include resources in PostScript file
  5. #
  6. # Copyright (C) Angus J. C. Duggan 1991-1995
  7. # See file LICENSE for details.
  8.  
  9. $prog = ($0 =~ s=.*/==);
  10.  
  11. %extn = ("font", ".pfa", "file", ".ps", "procset", ".ps", # resource extns
  12.      "pattern", ".pat", "form", ".frm", "encoding", ".enc");
  13. %type = ("%%BeginFile:", "file", "%%BeginProcSet:", "procset",
  14.      "%%BeginFont:", "font"); # resource types
  15.  
  16. sub filename {            # make filename for resource in @_
  17.    local($name);
  18.    foreach (@_) {        # sanitise name
  19.       s/[!()\$\#*&\\\|\`\'\"\~\{\}\[\]\<\>\?]//g;
  20.       $name .= $_;
  21.    }
  22.    $name =~ s@.*/@@;        # drop directories
  23.    die "Filename not found for resource ", join(" ", @_), "\n"
  24.       if $name =~ /^$/;
  25.    $name;
  26. }
  27.  
  28. while (<>) {
  29.    if (/^%%IncludeResource:/ || /^%%IncludeFont:/ || /^%%IncludeProcSet:/) {
  30.       local($comment, @res) = split(/\s+/);
  31.       local($type) = defined($type{$comment}) ? $type{$comment} : shift(@res);
  32.       local($name) = &filename(@res);
  33.       local($inc) = "/lib/psutils"; # system include directory
  34.       if (open(RES, $name) || open(RES, "$name$extn{$type}") ||
  35.       open(RES, "$inc/$name") || open(RES, "$inc/$name$extn{$type}")) {
  36.      while (<RES>) {
  37.         print $_;
  38.      }
  39.      close(RES);
  40.       } else {
  41.      print "%%IncludeResource: ", join(" ", $type, @res), "\n";
  42.      print STDERR "Resource $name not found\n";
  43.       }
  44.    } else {
  45.       print $_;
  46.    }
  47. }
  48. # End of Script
  49.